package com.teacold.utils.toast;

import android.content.Context;

import com.teacold.customdemo.R;

import java.util.Timer;
import java.util.TimerTask;

public class ToastTool {
     private static CustomToast mToast;

    public static void ToastTool(Context mContext,String mTips,int mImage,Long mTime){
        initToast(mContext,R.layout.toast_normal,mTips,mImage,mTime);
    }
    public static void ToastTool(Context mContext,String mTips,int mImage){
        initToast(mContext,R.layout.toast_normal,mTips,mImage,1500L);
    }
    public static void ToastTool(Context mContext,String mTips,Long mTime){
        initToast(mContext,R.layout.toast_normal,mTips,0,1500L);
    }
    public static void ToastTool(Context mContext,String mTips){
        initToast(mContext,R.layout.toast_normal,mTips,0,1500L);
    }
    private static  void initToast(Context mContext,int mLayout,String mTips ,int imaage,Long mTime){
        if(mToast==null){
            mToast=new CustomToast(mContext,mLayout,mTips,imaage);
        }else {
            mToast.initToast(mContext,mLayout,mTips,imaage);
        }
        final Timer timer =new Timer();
        timer.schedule(new TimerTask() {
            @Override
            public void run() {
                mToast.show();
            }
        },0,3000);
        new Timer().schedule(new TimerTask() {
            @Override
            public void run() {
                mToast.cancel();
                timer.cancel();
            }
        }, mTime);
    }




}
